package com.shop.cereshop.app.controller.buyer;

import com.shop.cereshop.app.annotation.NoRepeatSubmit;
import com.shop.cereshop.app.annotation.NoRepeatWebLog;
import com.shop.cereshop.app.param.follow.BuyerFollowDTO;
import com.shop.cereshop.app.service.follow.CereBuyerFollowService;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("follow")
@Slf4j(topic = "BuyerFollowController")
@Api(value = "关注模块", tags = "关注模块")
public class BuyerFollowController {

    @Resource
    private CereBuyerFollowService cereBuyerFollowService;

    @RequestMapping(value = "update", method = {RequestMethod.PUT, RequestMethod.POST})
    @ApiOperation(value = "更新关注")
    @NoRepeatWebLog
    @NoRepeatSubmit
    public Result updateFollow(@RequestBody BuyerFollowDTO  param, HttpServletRequest request) throws CoBusinessException {
        CereBuyerUser user = (CereBuyerUser) request.getAttribute("user");
        cereBuyerFollowService.updateFollow(param, user);
        return new Result<>(CoReturnFormat.SUCCESS);
    }
}
